package cn.hy.考试;

import java.util.*;

public class Main {

    private static int[][] grid;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();
        int c = sc.nextInt();
        grid = new int[r][c];
        sc.nextLine();

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                grid[i][j] = sc.nextInt();
            }
        }

        String ans = "";
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int count = countRowSign(i, j) + countColSign(i, j);
                ans += count + " ";
            }
        }
        System.out.println(r + " " + c);
        System.out.println(ans.substring(0, ans.length() - 1));

    }

    private static int countRowSign(int r, int c) {
        if (c == 0) {
            return 0;
        }
        int max = grid[r][c - 1];
        int count = 1;
        for (int i = c - 2; i >= 0; i--) {
            if (max >= grid[r][c]) {
                break;
            }
            int h = grid[r][i];
            if (h > max) {
                count++;
                max = h;
            }
        }
        return count;
    }


    private static int countColSign(int r, int c) {
        if (r == 0) {
            return 0;
        }
        int max = grid[r - 1][c]; //边界
        int count = 1;
        for (int i = r - 2; i >= 0; i--) {
            if (max >= grid[r][c]) {
                break;
            }
            int h = grid[i][c];
            if (h > max) {
                count++;
                max = h;
            }
        }
        return count;
    }


}
